
struct Uniform {
    ofs: f32,
};

struct Mats {
    MVP: mat4x4f,
    M: mat4x4f
}

struct vin {
    @location(0) pos: vec4f,
    @location(1) uv: vec2f, 
    @location(2) normal: vec4f,
}

struct v2f {
    @builtin(position) pos: vec4f,
    @location(1) uv: vec2f,
    @location(2) lambert: f32,
    @location(3) normal: vec3f
}

@group(0) @binding(1) var mainTex: texture_2d<f32>;
@group(0) @binding(2) var mainTexSampler: sampler;
@group(0) @binding(3) var<uniform> mats: Mats;

@vertex
fn vert(in: vin) -> v2f {
    var fakeNorm = normalize(in.pos);

    var out: v2f;
    out.pos = mats.MVP * (in.pos);
    out.uv = in.uv;
    out.lambert = dot(normalize((mats.M * in.normal).xyz), normalize(vec3f(-1, -1, -1)));
    out.normal = normalize((mats.M * in.normal).xyz);

    return out;
}

@fragment
fn frag(fin: v2f) -> @location(0) vec4f {
    return textureSample(mainTex, mainTexSampler, fin.uv) * saturate(fin.lambert * 0.5 + 0.5 + 0.3);
}
